home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9613 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  63 lines

  1. Path: news.acadia.net!usenet
  2. From: steven2@salesbook.com (Steve Nutt)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: What does TSomeObject *& SomeFunction(); mean
  5. Date: Sun, 03 Mar 1996 06:59:33 GMT
  6. Organization: DET
  7. Message-ID: <4hb7a3$9gm@post.acadia.net>
  8. References: <4h847u$5ha@ee.rutgers.edu>
  9. Reply-To: steven2@salesbook.com
  10. NNTP-Posting-Host: blf7.acadia.net
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. imranh@ee.rutgers.edu (Imran Hussain) wrote:
  14.  
  15. >Hi,
  16. >What is the difference between:
  17.  
  18. >TSomeObject*& SomeFunction();       and
  19. >TSomeObject*  SomeFunction();
  20.  
  21. >I know what the later means, but don't know the first one. Can
  22. >someone please help me out...
  23.  
  24.  
  25. >Thanks,
  26. >Imran
  27.  
  28. It returns a reference to a pointer to a TSomeObject.
  29.  
  30. As an example.
  31.  
  32.  
  33. class A
  34. {
  35. public:
  36.  A (void) {};
  37. };
  38.  
  39. class B
  40. {
  41. public:
  42.   B (void) { a = 0; }
  43.   A*& GetAndSetA (void) { return a; }
  44.  
  45. private:
  46.  A* a;
  47. };
  48.  
  49. main ()
  50. {
  51.   A a;
  52.   B b;
  53.   b.GetAndSetA() = &a;
  54.   A* aPointer = b.GetAndSetA();
  55.  
  56.   if (&a != aPointer)
  57.     throw "Either I've no idea what I'm talking about, or you've got a
  58. crummy compiler";
  59.  
  60.   return 0;
  61. }
  62.  
  63.